package org.administer.contaroller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.administer.dao.CrmDictionariesDao;
import org.administer.dao.CrmLossDao;
import org.administer.pojo.CrmDictionaries;
import org.administer.pojo.CrmLoss;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/loss")
public class LossController {
    @Autowired
    private CrmLossDao crmLossDao;
    @Autowired
    private CrmDictionariesDao crmDictionariesDao;
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(CrmLoss crmLoss) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmLossDao.add(crmLoss);
        return map;
    }
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,CrmLoss crmLoss) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<CrmLoss> pager= PageHelper.startPage(page,limit);
        List<CrmLoss> list=crmLossDao.getlist(crmLoss);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
    @RequestMapping("/lossindex")
    public String index(HttpSession session) throws Exception{
        List<CrmDictionaries> crmDictionaries= crmDictionariesDao.gettype("销售机会状态");
        session.setAttribute("crmDictionaries",crmDictionaries);
        return "customer/loss";
    }
    @RequestMapping("/search")
    @ResponseBody
    public Map<String,Object> credit() throws Exception{
        Map<String,Object> map=new HashMap<>();
        map.put("data",crmDictionariesDao.jihui());
        return map;
    }
}
